package com.etoak.common.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RedisUtil {

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    public void hset(String key,String field,String value){
        stringRedisTemplate.opsForHash().put(key,field,value);

    }

    public List<String> hvals(String key){
        return stringRedisTemplate.opsForHash().values(key).stream().map(Object::toString).toList();
    }

    public void hdel(String key,String... filed){
        stringRedisTemplate.opsForHash().delete(key,filed);
    }

    /**
     * 全局删除命令
     * @param key
     */
    public void deleteKey(String key){
        stringRedisTemplate.delete(key);
    }
}
